package com.xuecheng.content.contrller;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.service.iml.TeachplanServiceIml;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Slf4j
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
public class TeachplanController {

    private final TeachplanServiceIml teachplanServiceIml;

    @ApiOperation("查询课程计划信息")
    @GetMapping("/teachplan/{teachplanId}/tree-nodes")
    public List<TeachplanDto> queryTeachplanTreeNodes(@PathVariable Long teachplanId){

        return  teachplanServiceIml.queryTeachplanTreeNodes(teachplanId);
    }

    @ApiOperation("新增课程计划--章")
    @PostMapping("/teachplan")
    public void saveTeachplanTreeNodes(@RequestBody SaveTeachplanDto saveTeachplanDto){
        log.info("新增章节：{}",saveTeachplanDto);
        teachplanServiceIml.saveTeachplanTreeNodesZhang(saveTeachplanDto);
    }


    @ApiOperation("新增课程计划--节")
    @PostMapping("/content/teachplan")
    public void saveTeachplanTreeNodesJie(@RequestBody SaveTeachplanDto saveTeachplanDto){
        log.info("新增小节：{}",saveTeachplanDto);
        teachplanServiceIml.saveTeachplanTreeNodesZhang(saveTeachplanDto);
    }

    @ApiOperation("删除课程计划")
    @DeleteMapping("/teachplan/{id}")
    public void deleteTeachplan(@PathVariable Long id){
        log.info("删除课程计划：{}",id);
        teachplanServiceIml.deleteTeachplan(id);
    }


    @ApiOperation("向下移动课程计划")
    @PostMapping("/teachplan/movedown/{id}")
    public void moveDownTeachplan(@PathVariable Long id){
        log.info("向下移动课程计划：{}",id);
        teachplanServiceIml.moveDownTeachplan(id);
    }

    @ApiOperation("向上移动课程计划")
    @PostMapping("/teachplan/moveup/{id}")
    public void moveUpTeachplan(@PathVariable Long id){
        log.info("向下移动课程计划：{}",id);
        teachplanServiceIml.moveUpTeachplan(id);
    }


    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanServiceIml.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "删除课程计划和媒资信息绑定")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void deleteAssociationMedia(@PathVariable Long teachPlanId,@PathVariable String mediaId){
        teachplanServiceIml.deleteAssociationMedia(teachPlanId,mediaId);
    }


}
